pragma Singleton
import QtQuick 2.15

QtObject {
    id: cGlobal

    property var window: null
    property var viewer

    property int loadingTip:1

    function showMessage(parent, message ) {
//        if ( !window )
//        {
//            print( "showMessage: window is null" );
//            return;
//        }

        snakeBarComponent.createObject( parent, { text: message } );
    }

    function createObject(parent, url, properties ) {
        var component = Qt.createComponent( url );

        if ( component.status !== Component.Ready )
        {
            print( "createObjectAndOpen: create component errror:", url ,component. errorString());
            return null;
        }

        var result;

        if ( properties )
        {
            result = component.createObject(parent, properties );
        }
        else
        {
            result = component.createObject( parent );
        }

        if ( !result )
        {
            print( "createObject: create object errror:", url );
            return null;
        }

        return result;
    }

    function createObjectAndOpen(parent, url, properties ) {
        var component = Qt.createComponent( url );

        if ( component.status !== Component.Ready )
        {
            print( "createObjectAndOpen: create component errror:", url ,component. errorString());
            return null;
        }

        var result;

        if ( properties )
        {
            result = component.createObject( parent, properties );
        }
        else
        {
            result = component.createObject( parent );
        }

        if ( !result )
        {
            print( "createObjectAndOpen: create object errror:", url );
            return null;
        }

        result.open();
        return result;
    }

    property var snakeBarComponent: Component {

        CSnakeBar { }
    }
}
